/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layouts";
import EmptyLayout from "@/layouts/EmptyLayout";
import { routerMode } from "@/config/settings";

Vue.use(VueRouter);
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/choose",
    component: () => import("@/views/choose/index"),
    hidden: true,
  },
  {
    path: "/401",
    name: "401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true,
  }

];

export const asyncRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "index",
    children: [
      {
        path: "index",
        name: "Index",
        component: () => import("@/views/index/index"),
        meta: {
          title: "首页",
          icon: "home",
          affix: true,
          badge: "New",
        },
      },
    ],
  },
  {
    path: "/project",
    component: Layout,
    redirect: "noRedirect",
    name: "project",
    meta: { title: "工程管理", icon: "th-list", permissions: ["admin"] },
    children: [
      {
        path: "/project/workspace",
        name: "projectWorkspace",
        component: () =>
          import("@/views/project/workspace"),
        meta: { title: "工作空间" },
      },
      {
        path: "/project/list",
        name: "projectList",
        component: () =>
          import("@/views/project/list"),
        meta: { title: "工程项目" },
      },
      {
        path: "/project/info",
        name: "projectInfo",
        hidden: true,
        component: () =>
          import("@/views/project/info"),
        meta: { title: "工程详情" },
      },
      {
        path: "/project/add",
        name: "projectAdd",
        hidden: true,
        component: () =>
          import("@/views/project/add"),
        meta: { title: "工程详情" },
      },
      {
        path: "/project/text",
        name: "projectText",
        hidden: true,
        component: () =>
          import("@/views/project/text"),
        meta: { title: "文档中心" },
      },
      {
        path: "/project/statement",
        name: "projectStatement",
        component: () =>
          import("@/views/project/statement"),
        meta: { title: "报表统计" },
      }
    ],
  },
  // 用户管理
  {
    path: "/userManagement",
    component: Layout,
    redirect: "noRedirect",
    name: "userManagement",
    meta: { title: "用户管理", icon: "user", permissions: ["admin"] },
    children: [
      {
        path: "user/userList",
        name: "userUserList",
        component: () =>
          import("@/views/user/userList/index"),
        meta: { title: "用户列表" },
      },
      {
        path: "userPermissions",
        name: "Userpermissions",
        component: () =>
          import("@/views/user/permissions/index"),
        meta: { title: "权限设置" },
      },
      {
        path: "roleManagement",
        name: "RoleManagement",
        component: () =>
          import("@/views/personnelManagement/roleManagement/index"),
        meta: { title: "诚信评价" },
      }
    ],
  },
  {
    path: "/homeTest",
    component: Layout,
    redirect: "noRedirect",
    name: "PersonnelManagement",
    meta: { title: "系统首页", icon: "database", permissions: ["admin"] },
    children: [
      {
        path: "/homeTest1",
        name: "homeTest1",
        component: () =>
          import("@/views/adminTest/test.vue"),
        meta: { title: "系统首页1" },
      },
      {
        path: "/homeTest2",
        name: "homeTest2",
        component: () =>
          import("@/views/adminTest/test1.vue"),
        meta: { title: "系统首页2" },
      },

    ],
  },
  {
    path: "/error",
    component: EmptyLayout,
    redirect: "noRedirect",
    name: "Error",
    meta: { title: "错误页", icon: "bug" },
    children: [
      {
        path: "401",
        name: "Error401",
        component: () => import("@/views/401"),
        meta: { title: "401" },
      },
      {
        path: "404",
        name: "Error404",
        component: () => import("@/views/404"),
        meta: { title: "404" },
      },
    ],
  },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];

const router = new VueRouter({
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
});
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
/*const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};*/

export function resetRouter() {
  router.matcher = new VueRouter({
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher;
}

export default router;
